home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2937 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.5 KB  |  120 lines

  1. Path: news.kei.com!ub!newserve!rebecca!rpi!not-for-mail
  2. From: janc@pi.net (Jan Cornelis)
  3. Newsgroups: comp.lang.c++,comp.lang.c++.leda,comp.lang.c++.moderated
  4. Subject: Trees !, Who can help me to improve my trees code ! <janc@pi.net>
  5. Date: 20 Jan 1996 14:16:25 -0000
  6. Organization: Planet Internet
  7. Sender: cppmods@netlab.cs.rpi.edu
  8. Approved: devitto@ferndown.ate.slb.com
  9. Message-ID: <4dqtfp$ip5@netlab.cs.rpi.edu>
  10. NNTP-Posting-Host: netlab.cs.rpi.edu
  11. X-Original-Date: Sat, 20 Jan 1996 19:52:13 GMT
  12.  
  13. Who can help me with the following code written. The code doesn't work
  14. properly. I cannot understand why it doesn't work and how it should be
  15. improved. Is somebody there capable to help me out correcting this
  16. code ?
  17. Then i would like you to ask to help me either with a function in
  18. searching through the tree !
  19.  
  20. My e-mail adress:  janc@pi.net
  21.  
  22. #include<stdio.h>
  23. class jc
  24. {
  25.     public:
  26.     jc()
  27.     {
  28.        tail=NULL;
  29.        count = 0;
  30.     }
  31.  
  32.    // This function should add a value to the tree ! 
  33.    void addtree(int p);
  34.  
  35.    // This function should print one value from the tree one by one !
  36.    void onefurther();
  37.  
  38.    private:
  39.    struct list
  40.    {
  41.    //  'e' is the integer number for the tree !
  42.      int e;
  43.    //  The left side of the tree
  44.      list *left;
  45.    //  The right side of the tree
  46.      list *right;
  47.    };
  48.  
  49.    int count;
  50.    list *tail;
  51. };
  52.  
  53. void jc::addtree(int p)
  54. {
  55.     if (tel==0)
  56.    {
  57.      tailt = new list;
  58.      tail->links=NULL;
  59.      tail->rechts=NULL;
  60.      tailt=NULL;
  61.      tail->e=p;
  62.      tel++;
  63.    }
  64.    else
  65.    {
  66.       if (p < tail->e)
  67.       {
  68.         if (tail->left!=NULL)
  69.         {
  70.            tail->left = new list;
  71.            tail = tail->left;
  72.         }
  73.         else
  74.         {
  75.              tail = tail-> right;
  76.         }
  77.       }
  78.       else
  79.       {
  80.         if (tail->right != NULL)
  81.         {
  82.            tail->right = new list;
  83.            tail = tail->right;
  84.         }
  85.         else
  86.         {
  87.           tail = tail->right;
  88.         }
  89.       }
  90.    tail->left = NULL;
  91.    tail->right = NULL;
  92.    tail->e=p;
  93.    }
  94. }
  95.  
  96. void jc::onefurther()
  97. {
  98.    tail = tail->left;
  99.    printf("\nThe value  = %i",staart->e);
  100.    tail = tail->right;
  101. }
  102.  
  103. void main()
  104. {
  105.    jc a;
  106.    
  107.    for (int i=1;i <= 6;i++)   
  108.    a.addtail(i);
  109.  
  110.    for (int i=1;i <= 6;i++)   
  111.    a.onefurther();    
  112. }
  113.  
  114.  
  115.  
  116.       [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
  117.       [  Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm  ]
  118.       [  Moderation policy: http://www.connobj.com/cpp/guide.htm  ]
  119.       [      Comments? mailto:c++-request@netlab.cs.rpi.edu       ]
  120.